﻿package mortal.game.view.guildNew.WareHourse
{
    import mortal.common.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.guildNew.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewWHProcessor extends Object
    {
        private var _view:IView;

        public function GuildNewWHProcessor()
        {
            this.initServer();
            return;
        }// end function

        public function initView(param1:IView) : void
        {
            this._view = param1;
            return;
        }// end function

        public function initServer() : void
        {
            EventUtil.addNetEvent(ServerCommand.GuildWareHouseAllApplyNumUpdate, this.WareHouseAllApplyNumUpdate, true);
            return;
        }// end function

        public function onViewShow() : void
        {
            this.addEvs(true);
            return;
        }// end function

        public function onViewHide() : void
        {
            this.addEvs(false);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(EventName.Guild_wareHouse_getRecords, this.wareHouseGetRecords, param1);
            EventUtil.addNetEvent(ServerCommand.GuildWareHouseRecordsUpdate, this.WareHouseRecordsUpdate, param1);
            EventUtil.addSelfEvent(EventName.Guild_wareHouse_dealApplyList, this.wareHouseDealApply, param1);
            EventUtil.addNetEvent(ServerCommand.GuildWareHouseAllApplysUpdate, this.WareHouseAllApplysUpdate, param1);
            EventUtil.addSelfEvent(EventName.GuildParticipationInfoReq, this.onParticipationInfoReq, param1);
            EventUtil.addNetEvent(ServerCommand.GuildParticipationInfoRes, this.onResourceInfoRes, param1);
            EventUtil.addNetEvent(ServerCommand.GuildWarehouseAllocationSuccess, this.onallocationSuccess, param1);
            return;
        }// end function

        private function wareHouseGetRecords(event:DataEvent) : void
        {
            GameProxy.guild.getGuildWarehouseRecord();
            return;
        }// end function

        private function WareHouseRecordsUpdate(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewWareHPanel;
            if (_loc_2)
            {
                _loc_2.updateRecodePanel();
            }
            return;
        }// end function

        private function wareHouseDealApply(event:DataEvent) : void
        {
            GameProxy.guild.dealGuildWarehouseApply(event.data.opr, event.data.toPlayerId, event.data.uid, event.data.applyMoney);
            return;
        }// end function

        private function WareHouseAllApplysUpdate(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewWareHPanel;
            if (_loc_2)
            {
                _loc_2.updateApplyPanel();
            }
            return;
        }// end function

        private function WareHouseAllApplyNumUpdate(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            (this._view as GuildNewModule).updateApplyLabel();
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewWareHPanel;
            if (_loc_2)
            {
                _loc_2.updateApplyLabel();
            }
            return;
        }// end function

        private function onParticipationInfoReq(event:DataEvent) : void
        {
            GameProxy.guild.getGuildParticipationInfo();
            return;
        }// end function

        private function onResourceInfoRes(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewWareHPanel;
            if (_loc_2)
            {
                _loc_2.updateResourcePanel(param1);
            }
            return;
        }// end function

        private function onallocationSuccess(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewWareHPanel;
            if (_loc_2)
            {
                _loc_2.onallocationSuccess(param1);
            }
            return;
        }// end function

    }
}
